//基于数组实现栈
interface stackArray<T>{
    //栈存放的值
    [index: number]: T;
    //栈的长度
    length: number;
    //入栈方法
    inStack(ele: T): T;
    //出栈方法
    outStack(): T;
    //获取栈顶
    stackTop(): T;
    //获取栈长度
    size(): number;
    //将数据转成字符串
    toString():string
}
class StackArray<T> implements stackArray<T>{
    [index: number]: T;
    length: number=0;
    constructor(...ele:T[]) {
        if (ele.length > 0) {
            for (let index = 0; index < ele.length;index++){
                this[index] = ele[index]
                this.length++
            }
        }
    }

    inStack(ele: T): T{
        this[this.length++]=ele
        return ele
    }

    outStack(): T{
        const val:T = this[this.length-1]
        delete this[this.length - 1]
        this.length--
        return val
    }

    stackTop(): T{
        return this[this.length-1]
    }

    size(): number{
        return this.length
    }

    toString(): string{
        let str: string = ""
        for (let index = 0; index < this.length; index++) {
            str += this[index]
        }
        return str
    }

    private splice(){}
}
export {
    StackArray
}